package com.foreknow.test730;

import java.util.List;
import java.util.Scanner;

/**
 * @author shkstart
 * @create 2021-07-30 15:56
 */
public class view {
    public void showview() {
        Scanner sc = new Scanner(System.in);
        boolean flag = true;
        Do d = new Do();
        List<Student> startstu = d.getAll();
        while (flag) {
            d.show(startstu);
            System.out.println("1.添加学生 2.删除学生 3.修改学生 4.查询学生 5.退出");
            System.out.println("请输入（1-5）");
            String sel = sc.next();
            char key = sel.charAt(0);
            switch (key) {
                case '1':
                    Student student = add1();
                    boolean add = d.add(student);
                    if (add) {
                        System.out.println("添加成功");
                    }
                    break;
                case '2':
                    String del = del();
                    boolean del1 = d.del(del);
                    if(del1){
                        System.out.println("删除成功");
                    }else {
                        System.out.println("删除失败");
                    }
                    break;
                case '3':
                    String update = update();
                    Student stuById = d.getStuById(update);
                    if(stuById!=null){
                        Student student1 = d.upDtedById(stuById);
                        if(student1!=null){
                            System.out.println("修改成功");
                        }
                    }else {
                        System.out.println("未找到学生，修改失败");
                    }

                    break;
                case '4':
                    String findid = findid();
                    Student stuById1 = d.getStuById(findid);
                    if(stuById1!=null){
                        System.out.println("找到了");
                        stuById1.toString();
                    }else {
                        System.out.println("未找到");
                    }


                    break;
                case '5':

                    boolean isend=true;
                    while(isend){
                        System.out.println("是否确认退出(Y/N)");
                        String end=sc.next();
                        char cend=end.toUpperCase().charAt(0);
                        if(cend=='Y'){
                            isend=false;
                            flag = false;
                        }else if(cend=='N'){
                            break;
                        }else {
                            System.out.println("输入错误请重新输入");
                        }
                    }
                    break;
            }
        }

    }

    public Student add1() {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入id");
        String id = input.next();
        System.out.println("请输入姓名");
        String name = input.next();
        System.out.println("请输入年龄");
        int age = input.nextInt();
        Student stu1 = new Student(id, name, age);
        return stu1;
    }

    public String del() {
        System.out.println("请输入要删除学生的id");
        Scanner input = new Scanner(System.in);
        String delid = input.next();
        return delid;
    }
    public String update(){
        System.out.println("请输入要修改学生的id");
        Scanner input = new Scanner(System.in);
        String update = input.next();
        return update;
    }
    public String findid(){
        System.out.println("请输入要查询学生的id");
        Scanner input = new Scanner(System.in);
        String find = input.next();
        return find;
    }


    public static void main(String[] args) {
        view v1 = new view();
        v1.showview();
    }


}
